/*   Copyright 2012 Julian Aloofi

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#include "Common.hpp"

Tacticus::Common::Coordinate::Coordinate(float x, float y) : x(x), y(y)
{
}

Tacticus::Common::Coordinate::Coordinate(sf::Vector2f vector) :
    x(vector.x), y(vector.y)
{
}

bool Tacticus::Common::Coordinate::operator==(
    const Tacticus::Common::Coordinate &rhs) const
{
    return (x == rhs.x && y == rhs.y);
}

bool Tacticus::Common::Coordinate::operator!=(
    const Tacticus::Common::Coordinate &rhs) const
{
    return !(*this == rhs);
}

Tacticus::Common::Coordinate Tacticus::Common::Coordinate::operator+(const
    Tacticus::Common::Coordinate &rhs) const
{
    return Coordinate(x + rhs.x, y + rhs.y);
}

Tacticus::Common::Coordinate Tacticus::Common::Coordinate::operator-(const
    Tacticus::Common::Coordinate &rhs) const
{
    return Coordinate(x - rhs.x, y - rhs.y);
}

bool Tacticus::Common::isOnTheBoard(const Tacticus::Common::Coordinate &x)
{
    if (x.x > 9.f || x.x < 0.f || x.y > 9.f || x.y < 0.f)
        return false;
    else
        return true;
}

bool Tacticus::Common::areOnTheBoard(const Tacticus::Common::Coordinate &x,
    const Tacticus::Common::Coordinate &y)
{
    if (isOnTheBoard(x) && isOnTheBoard(y))
        return true;
    else
        return false;
}

bool Tacticus::Common::isOnTheScreen(const Tacticus::Common::Coordinate &x)
{
    if (x.x > 12.f || x.x < 0.f || x.y > 12.f || x.y < 0.f)
        return false;
    else
        return true;
}

size_t Tacticus::Common::findStr(std::string &string, std::string searchFor)
{
    size_t found = string.find(searchFor);
    if (found == std::string::npos)
        throw AssumptionException("Did not find seperator \"" + searchFor +
            "\" while searching in \"" + string + "\"");
    return found;
}
